home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / lib / Integer.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  2KB  |  97 lines

  1. /* Integer.c -- implementation of Integer object
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet: kgorlen@alw.nih.gov
  20.     September, 1985
  21.  
  22. Function:
  23.     
  24. Provides an object that contains an int.
  25.  
  26. $Log:    Integer.c,v $
  27.  * Revision 3.0  90/05/20  00:19:53  kgorlen
  28.  * Release for 1st edition.
  29.  * 
  30. */
  31.  
  32. #include "Integer.h"
  33. #include "nihclIO.h"
  34.  
  35. #define    THIS    Integer
  36. #define    BASE    Object
  37. #define BASE_CLASSES BASE::desc()
  38. #define MEMBER_CLASSES
  39. #define VIRTUAL_BASE_CLASSES Object::desc()
  40.  
  41. DEFINE_CLASS(Integer,1,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Integer.c,v 3.0 90/05/20 00:19:53 kgorlen Rel $",NULL,NULL);
  42.  
  43. Integer::Integer(istream& strm)        { parseInteger(strm); }
  44.  
  45. unsigned Integer::hash() const { return val; }
  46.  
  47. bool Integer::isEqual(const Object& ob) const
  48. {
  49.     return ob.isSpecies(classDesc) && val==castdown(ob).val;
  50. }
  51.  
  52. const Class* Integer::species() const { return &classDesc; }
  53.  
  54. int Integer::compare(const Object& ob) const
  55. {
  56.     assertArgSpecies(ob,classDesc,"compare");
  57.     long t = val-castdown(ob).val;
  58.     if (sizeof(long) > sizeof(int)) {
  59.         if (t < 0) return -1;
  60.         return (t > 0);
  61.     }
  62.     return t;
  63. }
  64.  
  65. void Integer::deepenShallowCopy()    {}
  66.  
  67. void Integer::printOn(ostream& strm) const
  68. {
  69.     strm << val;
  70. }
  71.  
  72. void Integer::scanFrom(istream& strm)    { parseInteger(strm); }
  73.  
  74. Integer::Integer(OIOin& strm)
  75.     : BASE(strm)
  76. {
  77.     strm >> val;
  78. }
  79.  
  80. void Integer::storer(OIOout& strm) const
  81. {
  82.     BASE::storer(strm);
  83.     strm << val;
  84. }
  85.  
  86. Integer::Integer(OIOifd& fd)
  87.     : BASE(fd)
  88. {
  89.     fd >> val;
  90. }
  91.  
  92. void Integer::storer(OIOofd& fd) const
  93. {
  94.     BASE::storer(fd);
  95.     fd << val;
  96. }
  97.